/**
 * 字符串工具类
 */
import dayjs from "dayjs";

/**
 * 获取年月日时分秒数字
 */
export const getDateYToSNum = () => dayjs().format("YYYYMMDDHmmss");

export const getDateYToS = (date) => dayjs(date).format("YYYY/MM/DD H:mm:ss");


/**
 * 获取天数
 */
export const getDateDay = time => Number(dayjs(time).format("DD"));
/**
 * 驼峰映射工具类
 * @param str
 * @constructor
 */
export const DataToCamelCase = (str: string) => {
    return str.replace(/_./g, (match) => match.charAt(1).toUpperCase());
}

/**
 * 从a*b中提取a和b
 */

export const getAANDB = (str: string) => {
    return str.match(/(\d+)/g) || [];
}

/**
 * 产品总表方法：获取直径*直径*高
 * @param arr
 */
export const getFormula = (arr: Array<number>) => {
    return arr[0] * arr[0] * arr[1]
}

/**
 * 根据序号生成字母（Excel列名）
 * @param index
 */
export const generateLetter = (index:number) => {
        const baseCharCode = 65; // ASCII码中字母A的值
        const numLetters = 26; // 字母总数
        let result = "";

        const generate = (num) => {
            if (num <= 0) {
                return;
            }

            const letterIndex = (num - 1) % numLetters; // 取余数，确保在0到25之间
            const charCode = baseCharCode + letterIndex; // 计算字母的ASCII码
            const letter = String.fromCharCode(charCode); // 转换为字母

            result = letter + result;

            generate(Math.floor((num - 1) / numLetters));
        };

        generate(index);

        return result;
}

/**
 * 寻找数组最大值
 * @param arr
 */
export const findMaxValue = (arr:number[]) => {
  if (arr.length === 0){
    return null;
  }

  let max = Number.MIN_SAFE_INTEGER

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] > max){
      max = arr[i]
    }
  }

  return max;
}